<?php 
class export_employ_m extends MY_Model{
	function __construct(){
		parent::__construct();
		$this->list_employ = array();
	}
	public function get_room($id_room,$post,$excel)
	{
		$id_room = (!empty($id_room))?$id_room:0;
		if(count($id_room) > 0)
		for($i=0;$i<count($id_room);$i++)
			$this->db->or_where("room.id",$id_room[$i]);	 
		$room = $this->db->get("emp_room room")->result_array();
		$i=0;
		foreach($room as $item){
			$this->get_employ($item["id"],$post,$excel);
			$this->get_roomparent($item["id"],$post,$excel);
		}
		return array_filter($this->list_employ);
	}
	function get_roomparent($parent_id,$post,$excel){
		$this->db->where("parent_id",$parent_id);
		$data_parent = $this->db->get("emp_room")->result_array();
		if(!empty($data_parent)){
			foreach($data_parent as $item){
				$this->get_employ($item["id"],$post,$excel);
				$this->get_roomparent($item["id"],$post,$excel);
			}
		}
		return; 
	}
	function get_room_em($id_em){
		return $this->db->select("room_id")->from("emp_profile")->where("id",$id_em)->get()->row_array();
	}
	function get_employ($id_room,$post,$excel){
		$this->db->where("profile.room_id",$id_room);
		if(!empty($post)){
			for($i=0;$i<count($post);$i++){
				$array_table = explode(",",$post[$i]);
				if(!empty($array_table) and count($array_table)>1){
					for($j=0;$j<count($array_table);$j++){
						$this->db->select($array_table[$j]);
					}
				}
				else
					$this->db->select($post[$i]);
			}
		}
		else{
			foreach($excel as $value => $name){
				$this->db->select($value);
			}
		}		
		$this->db->join("emp_profile profile","profile.id = users.id");
		$this->db->join("emp_room room","room.id = profile.room_id");
		$this->db->join("ser_groups groups","users.group_id = groups.id");
		$this->db->from("ser_users users");
		$data = $this->db->get()->result_array();
		foreach($data as $item_em){
			$this->list_employ[] = $item_em;
		}
	}
}